import { Http } from "../utils/http";

class Theme {
  static locationA = "t-1";
  static locationE = "t-2";
  static locationF = "t-3";
  static locationH = "t-4";

  themes = []; // 保存全部主题

  // 获取全部主题
  async getThemes() {
    const names = `${Theme.locationA},${Theme.locationE},${Theme.locationF},${Theme.locationH}`;
    this.themes = await Http.request({
      url: "/v1/theme/by/names",
      method: "GET",
      data: {
        names,
      },
    });
  }

  // 首页顶部主题
  async getHomeLocationA() {
    return this.themes.find((t) => t.name === Theme.locationA);
  }
  // 获取主页SPU滚动主题
  async getHomeLocationE() {
    return this.themes.find((t) => t.name === Theme.locationE);
  }

  // 获取主页SPU滚动主题下图片
  async getHomeLocationF() {
    return this.themes.find((t) => t.name === Theme.locationF);
  }
  // 获取主页单图片
  async getHomeLocationH() {
    return this.themes.find((t) => t.name === Theme.locationH);
  }

  async getHomeLocationESpu() {
    return this.getThemeSpuByName(Theme.locationE);
  }
  // 根据名称获取spu主题
  async getThemeSpuByName(name) {
    return await Http.request({
      url: `/v1/theme/name/${name}/with_spu`,
      method: "GET",
    });
  }
}

export { Theme };
